﻿@{
    ViewBag.Title = "Update";
    Layout = "~/Views/Shared/_Admin_Layout.cshtml";
    ViewBag.Controller = "place";
    ViewBag.Cate = "Địa Danh";
    ViewBag.Module = "Add New Location";
}

<script type="text/javascript">
    $(function () {
        //Geocompete
        $("#geocomplete").geocomplete({
            details: "#alternatecolor"
        });

        $('#_btn_add').live('click', function () {
            var name = $("#_name").val();
            var address = $("#geocomplete").val();

            var editor = CKEDITOR.instances.editor;
            $("textarea#editor").text(editor.getData()).text();

            var description = $("#editor").val();

            //Check Name
            if (name == '') {
                show_errors("Chưa nhập tên địa danh.");
                return false;
            }

            //Check Address
            if (address == '') {
                show_errors("Chưa nhập địa chỉ.");
                return false;
            }

            UpdateItem("@ViewBag.Controller");

            return false;
        });
    });

    function BrowseServerImage(startupPath, functionData) {
        var finder = new CKFinder();
        finder.basePath = '../';
        finder.startupPath = startupPath;
        finder.selectActionFunction = SetFileField;
        finder.selectActionData = functionData;
        finder.popup();
    }

    function SetFileField(fileUrl, data) {
        document.getElementById(data["selectActionData"]).value = fileUrl;
    }
</script>

<!--Tabs-->
<div class="tabs">
    <span class="item"><a href="/admin" title="">Bảng điều khiển</a></span>
    <span class="icon-arrow">&gt;</span>
    <span class="item"><a href="/admin/@ViewBag.Controller" title="">@ViewBag.Cate</a></span>
    <span class="icon-arrow">&gt;</span>
    <span class="item">Cập nhật</span>
</div>
<!--End Tabs-->

<!--Container-->
<div class="container">
	<form class="table-content" id="_PostData" method="post">
        <div class="list-btn">
            <a href="/admin/@ViewBag.Controller" class="btn btn-primary" title="Danh sách">Danh sách</a>
            @if (ViewBag.View == null)
            { 
                <input type="submit" class="btn btn-success" id="_btn_add" value="Lưu" />
            }
            else
            {
                <input type="submit" class="btn btn-warning" id="_btn_add" value="Cập nhật" />
            }
        </div>
        <div class="clearAll"></div>
        <div class="notice"><span class="close-notice icon-remove"></span></div>
		<div class="title"><span class="icon-user"></span>@ViewBag.Module</div>
		<div class="error"></div>
		<div class="box-field">
            <input type="hidden" name="id" id="_id" value="@if(ViewBag.View != null){@ViewBag.View.id}"/>
            <table class="altrowstable" id="alternatecolor">
                <tr>
                    <th>Tên Field</th><th>Input Field</th>
                </tr>
                <tr>
                    <td>Tên địa danh</td>
                    <td><input type="text" name="name" id="_name" value="@if (ViewBag.View != null){ @ViewBag.View.name }" placeholder="Ex: Hồ con rùa" maxlength="50" /></td>
                </tr>
                <tr>
                    <td>Giới thiệu</td>
                    <td><textarea name="description" id="editor" class="span9" style="height:100px">@if (ViewBag.View != null){ @ViewBag.View.description }</textarea></td>
                </tr>
                <tr>
                    <td>Hình ảnh chuyên mục</td>
                    <td>
                        <input type="text" name="image" id="xImagePath" class="span5" value="@if (ViewBag.View != null){ @ViewBag.View.image }" />
                        <input type="button" class="btn btn-danger" value="Browse Server" onclick="BrowseServerImage('Images:/', 'xImagePath');" />
                    </td>
                </tr>
                <tr>
                    <td>Địa chỉ</td>
                    <td><input type="text" name="address" id="geocomplete" value="@if (ViewBag.View != null){ @ViewBag.View.address }" placeholder="Ex: 232 Cộng Hoà, Tan Binh District, Ho Chi Minh City, Vietnam" /></td>
                    
                </tr>
                <tr>
                    <td>Latitude</td>
                    <td><input type="text" name="lat" value="@if (ViewBag.View != null){ @ViewBag.View.latitude.Trim() }" placeholder="Ex: 11.951343" /></td>
                </tr>
                <tr>
                    <td>Longitude</td>
                    <td><input type="text" name="lng" value="@if (ViewBag.View != null){ @ViewBag.View.longitude.Trim() }" placeholder="Ex: 108.448765"  /></td>
                </tr>
                <tr>
                    <td>Trạng thái</td>
                    <td><input type="checkbox" name="status" id="_status" value="1" @if (ViewBag.View != null && @ViewBag.View.status == 1) { Write("checked"); } /></td>
                </tr>
            </table>
		</div>
	</form>         
</div>
<!--End Container-->

<script>
    // Replace the <textarea id="editor1"> with an CKEditor instance.
    CKEDITOR.replace('editor');
</script>